<?php

namespace App\Models\Entity\Asset\Vlive;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Vepg
 * @package App\Models\Entity\Asset\Vlive
 * @version December 11, 2017, 10:26 am CST
 *
 * @property \App\Models\Entity\Asset\Vlive\Vchan vchan
 * @property \App\Models\Entity\Asset\Vlive\EpgFormat epgFormat
 * @property string vepg_no
 * @property string Vchan
 * @property string name
 * @property string title
 * @property string subtitle
 * @property string epg_url
 * @property string epg_format_id
 * @property string short_desc
 * @property string long_desc
 * @property timestamp start_time
 * @property timestamp end_time
 * @property timestamp created_at
 * @property timestamp updated_at
 */
class Vepg extends Model
{
    use SoftDeletes;


    public $table = 'vepgs';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'vepg_no',
        // 'vchan_id',
        'name',
        'title',
        'subtitle',
        'epg_url',
        'epg_format_id',
        'short_desc',
        'long_desc',
        'listorder',
        'start_time',
        'end_time',
        'created_at',
        'created_at',
        'updated_at'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'vepg_no' => 'string',
        // 'vchan_id' => 'integer',
        'name' => 'string',
        'title' => 'string',
        'subtitle' => 'string',
        'epg_url' => 'string',
        'epg_format_id' => 'integer',
        'short_desc' => 'string',
        'long_desc' => 'string',
        'listorder' => 'integer'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'vepg_no' => 'required|max:100|unique:vepg,vepg_no',
        'name' => 'required',
        'title' => 'required',
        'epg_url' => 'required',
        'start_time' => 'datetime',
        'end_time' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     **/
    // public function vchan()
    // {
    //     return $this->belongsTo(\App\Models\Entity\Asset\Vlive\Vchan::class, 'id');
    // }
    // public function vchan()
    // {
    //     return $this->hasOne(\App\Models\Entity\Asset\Vlive\Vchan::class, 'id', 'vchan_id');
    // }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function epgFormat()
    {
        return $this->hasOne(\App\Models\Common\EnumData\Vlive\EpgFormat::class, 'id', 'epg_format_id');
    }
}
